/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Test;

import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.poi.hssf.usermodel.HSSFClientAnchor;
import org.apache.poi.hssf.usermodel.HSSFPatriarch;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

/**
 *
 * @author Administrador
 */
public class MyWorkBook {

    public static void main(String[] args) {
//        int col = 1, row = 1;
        HSSFWorkbook wb = new HSSFWorkbook();
        HSSFSheet testsheet = wb.createSheet("test");
        System.out.println("The work book is created");
        try {
            FileOutputStream fos = new FileOutputStream("sample.xls");
            System.out.println("File sample.xls is created");
            FileInputStream fis = new FileInputStream("logo_promesa.jpg");
            ByteArrayOutputStream img_bytes = new ByteArrayOutputStream();
            int b;
            while ((b = fis.read()) != -1) {
                img_bytes.write(b);
            }
            fis.close();
            HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 0, 0, (short) 0, 0, (short) 5, 3);
            int index = wb.addPicture(img_bytes.toByteArray(), HSSFWorkbook.PICTURE_TYPE_JPEG);
            HSSFSheet sheet = wb.getSheet("test");
            HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
            patriarch.createPicture(anchor, index);
            anchor.setAnchorType(2);
            wb.write(fos);
            System.out.println("Writing data to the xls file");
            fos.close();
            System.out.println("File closed");
        } catch (IOException ioe) {
            System.out.println("Hi ! You got an exception. " + ioe.getMessage());
        }
    }
}
